package cn.dliyy.warehouse.controller;

import java.util.List;

import javax.annotation.Resource;
import javax.validation.Valid;

import org.springframework.stereotype.Controller;
import org.springframework.ui.ModelMap;
import org.springframework.validation.BindingResult;
import org.springframework.web.bind.annotation.ModelAttribute;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;

import cn.dliyy.warehouse.bean.BDealer;
import cn.dliyy.warehouse.service.BDealerService;

@Controller
@RequestMapping(value = "/dealer")
public class BDealerController {

	@Resource
	private BDealerService bDealerService;
	@Resource
	private BDealer bDealer;

	@RequestMapping(value ={"", "/"})
	public String load(ModelMap modelMap) {
		List<?> list = bDealerService.getList(BDealer.class);
		modelMap.put("list", list);
		return "/base/dealer";
	}

	@RequestMapping(value = "/add", method = RequestMethod.GET)
	public String create(ModelMap modelMap) {
		modelMap.addAttribute("dealer",bDealer);
		return "/base/dealer_add";
	}

	@RequestMapping(value = "/add", method = RequestMethod.POST)
	public String create(@Valid @ModelAttribute("dealer") BDealer bDealer, BindingResult result, ModelMap mp) {
		bDealerService.save(bDealer);
		return "redirect:/dealer/";
	}

}
